package com.pesking.core.sqlparser.processor;

import java.util.Arrays;
import java.util.List;

import com.pesking.core.parameter.Parameter;
import com.pesking.core.sqlparser.parameter.SqlParameter;
import com.pesking.core.sqlparser.parameter.SqlParameterProcessor;
import com.pesking.core.util.StringUtils;

public class AllMatchSqlParameterHandler extends SqlParameterProcessor {

	@Override
	public String getTitle() {
		return "全匹配参数";
	}

	@Override
	public String getDescription() {
		return  this.getTitle() + ",自动在参数前后加上%，进行全量匹配。";
	}

	@Override
	public String getUsage() {
		return "[AV:参数名]";
	}

	@Override
	public List<String> getSqlParameterType() {
		return Arrays.asList(new String []{"AV"});
	}

	@Override
	public void handle(StringBuilder sbSQL,
			Parameter parameter, List<SqlParameter> processors,SqlParameter sqlParameter) {
		String value = parameter.getParameter(sqlParameter.getName());
		if (StringUtils.isBlank(value)){
			sbSQL.append("null");
		}
		else{
			value = formatValue(value);
			sbSQL.append("'%").append(value).append("%'");
		}
	}

}
